<!-- 1、状态是不可逆的只能从pending到fulfilled或rejected,且状态改变后不能再改变
2、传入原因 -->

<script>
  const PENDING = 'pending'
  const FULFILLED = 'fulfilled'
  const REJECTED = 'rejected'
  class MyPromise{
    constructor(executor){
      this.state = PENDING
      this.result = undefined
      const resolve = (result)=>{
        console.log('result:',result)
        if(this.state === PENDING) {
          this.state = FULFILLED
          this.result = result
        }
      }
      const reject = (result)=>{
         console.log('result:',result)
         if(this.state === PENDING) {
          this.state = REJECTED
          this.result = result
         }
      }
      executor(resolve,reject)
    }
  }

  const p1 = new MyPromise((resolve, reject) => {
    resolve(1)
    // reject(11)
  })
  console.log(p1.state)
  console.log(p1.result)
</script>